//时间格式转换
function dateFormat(value, type) {
	if (!value) return '';
	let time = new Date(value * 1000);

	function timeAdd0(str) {
		if (str < 10) {
			switch (type) {
				case 'min':
					str = str;
					break;
				case 'day':
					str = '0' + str;
					break;
			}
		}
		return str;
	}
	let y = time.getFullYear();
	let m = time.getMonth() + 1;
	let d = time.getDate();
	let h = time.getHours();
	let mm = time.getMinutes();
	let s = time.getSeconds();
	switch (type) {
		case 'min':
			return `${timeAdd0(m)}`;
			break;
		case 'day':
			return `${timeAdd0(y)}.${timeAdd0(m)}.${timeAdd0(d)} ${timeAdd0(h)}:${timeAdd0(mm)}`;
			break;
			
	}
	// if (type == 'min') {
	// 	return `${timeAdd0(m)}min`;
	// } 
}
//倒计时
function countDown(endTime, type) {
	var nowtime = new Date() //获取当前时间
	var lefttime = (endTime * 1000) - nowtime.getTime(), //距离结束时间的毫秒数
		leftd = Math.floor(lefttime / (1000 * 60 * 60 * 24)), //计算天数
		lefth = Math.floor(lefttime / (1000 * 60 * 60) % 24), //计算小时数
		leftm = Math.floor(lefttime / (1000 * 60) % 60), //计算分钟数
		lefts = Math.floor(lefttime / 1000 % 60); //计算秒数
	if(leftd == 0 && lefth == 0 && leftm == 0 && lefts == 0){
		return 'clear'
	}
	function timeAdd0(str) {
		if (str < 10) {
			str = '0' + str;
		}
		return str;
	}
	switch (type) {
		case 'day':
			return `${timeAdd0(leftd)}天${timeAdd0(lefth)}时${timeAdd0(leftm)}分${timeAdd0(lefts)}秒`;
			break;
		case 'dayType':
			return `${timeAdd0(leftd)}d ${timeAdd0(lefth)}:${timeAdd0(leftm)}:${timeAdd0(lefts)}`;
			break;
	}
	
}

//单位超出10000 显示w
function format(num, type) {
	console.log(1111111,type)
	if (num >= 1e4) {
		return parseInt(num / 1e4) + (type == 'eng' ? `w` : '万')
	} else {
		return num
	}
}

export {
	dateFormat,
	format,
	countDown
}
